package com.cndw.kungfu.model.business;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cndw.kungfu.config.ConstantsIntKey;
import com.cndw.kungfu.domain.Player;
import com.cndw.kungfu.domain.Recharge;
import com.cndw.kungfu.ext.TimeProcesser;

@Service
public class IBusinessServer {

	@Resource
	private IConstantsConfigManger configManger;
	@Autowired
	private IPayManager iPayManager;
	@Autowired
	private IPlayerManager iPlayerManager;

	public boolean updateConfig(String name, String configValue) {
		return configManger.updateConfig(name, configValue);
	}

	public int selectPayGoldSum(long playerId) {
		return iPayManager.selectPayGoldSum(playerId);
	}
	
	public int selectPayGoldSumOnlyQQPay(long playerId) {
		return iPayManager.selectPayGoldSumOnlyQQPay(playerId);
	}
	
	public Recharge selectFirst(long playerId){
		return iPayManager.selectFirst(playerId);		
	}

	public int payInsertDB(Player player, String transactionId, float money, int gold, int exchangeType) {
		return payInsertDB(player, transactionId, 0, money, gold, exchangeType, 0, 0,gold);
	}

	public int payInsertDB(Player player, String transactionId, int addcoin, float money, int gold, int exchangeType, float depay, float gDepay,int goldAll) {
		Recharge recharge = new Recharge();
		recharge.setAccountName(player.getAccountName());
		recharge.setPlayerId(player.getPlayerId());
		recharge.setPlayerName(player.getPlayerName());
		recharge.setTransactionId(transactionId);
		recharge.setAddcoin(addcoin);
		recharge.setMoney(money);
		recharge.setGold(gold);
		recharge.setExchangeType(exchangeType);
		recharge.setDepay(depay);
		recharge.setgDepay(gDepay);
		recharge.setCreateDate(TimeProcesser.getUnixTime());
		recharge.setState(2);
		recharge.setGoldAll(goldAll);
		return iPayManager.insert(recharge);
	}

	public Recharge selectRecharge(long playerId, int id, int activitybegintime) {		
		return iPayManager.selectRecharge(playerId,id,activitybegintime);
	}
	
	public int selectPeriodPaySum(Player player, int beginTime, int endTime) {
		if (player.getDataInfo().intDataGet(ConstantsIntKey.payCash) <= 0) {
			return 0;
		}
		return iPayManager.selectPeriodPaySum(player.getPlayerId(), beginTime, endTime);
	}
	
	public Map<String, Integer> getOnLine(int scends){		
		return iPlayerManager.getOnLine(scends);
	}
}
